<?php
/***********************************************************
	Filename: app/admin/order.php
	Note	: 订单管理
	Version : 3.0
	Author  : qinggan
	Update  : 2009-12-23
***********************************************************/
class order_c extends Control
{
	function __construct()
	{
		parent::Control();
		$this->load_model("order");
	}

	//兼容PHP4的写法
	function order_c()
	{
		$this->__construct();
	}

	function index_f()
	{
		sys_popedom("order:list","tpl");
		$pageid = $this->trans_lib->int(SYS_PAGEID);
		$offset = $pageid>0 ? ($pageid-1)*SYS_PSIZE : 0;
		$condition = " 1=1 ";
		$startdate = $this->trans_lib->safe("startdate");
		$page_url = $this->url("order");
		if($startdate)
		{
			$this->tpl->assign("startdate",$startdate);
			$condition .= " AND o.postdate>='".strtotime($startdate)."'";
			$page_url .= "startdate=".rawurlencode($startdate)."&";
		}
		$enddate = $this->trans_lib->safe("enddate");
		if($enddate)
		{
			$this->tpl->assign("enddate",$enddate);
			$condition .= " AND o.postdate<='".strtotime($enddate)."'";
			$page_url .= "enddate=".rawurlencode($enddate)."&";
		}
		//判断是否已付款
		$ifpay = $this->trans_lib->int("ifpay");
		if($ifpay)
		{
			$this->tpl->assign("ifpay",$ifpay);
			$condition .= " AND o.pay_status='".($ifpay == 1 ? 1 : 0)."'";
			$page_url .= "ifpay=".$ifpay."&";
		}
		$status = $this->trans_lib->int("status");
		if($status)
		{
			$this->tpl->assign("status",$status);
			$condition .= " AND o.status='".($status == 1 ? 1 : 0)."'";
			$page_url .= "status=".$status."&";
		}
		$total = $this->order_m->get_count($condition);
		$rslist = $this->order_m->get_list($offset,$condition);
		$this->tpl->assign("total",$total);
		$this->tpl->assign("rslist",$rslist);
		$pagelist = $this->page_lib->page($page_url,$total);
		$this->tpl->assign("pagelist",$pagelist);
		$this->tpl->display("order/list.html");
	}

	function status_f()
	{
		$id = $this->trans_lib->int("id");
		if(!$id)
		{
			exit("error: 没有指定ID");
		}
		sys_popedom("order:check","ajax");
		$rs = $this->order_m->get_one($id);
		$status = $rs["status"] ? "0" : "1";
		$this->order_m->status($id,$status);
		exit("ok");
	}

	function del_f()
	{
		$id = $this->trans_lib->int("id");
		if(!$id)
		{
			exit("error: 没有指定ID");
		}
		sys_popedom("order:delete","ajax");
		$this->order_m->del($id);
		exit("ok");
	}

	function show_f()
	{
		sys_popedom("order:list","tpl");
		$id = $this->trans_lib->int("id");
		if(!$id)
		{
			error("错误，没有指这ID");
		}
		sys_popedom("order:list","tpl");
		$rs = $this->order_m->get_one($id);
		$this->tpl->assign("rs",$rs);
		$rslist = $this->order_m->get_products($id);
		$this->tpl->assign("rslist",$rslist);
		if($rs["pay_type"])
		{
			$this->load_model("payment");
			$pay_rs = $this->payment_m->get_one($rs["pay_type"]);
			$this->tpl->assign("pay_rs",$pay_rs);
		}
		$this->tpl->display("order/show.html");
	}
}
?>